var express = require('express');
var router = express.Router();
var redis = require('../lib/redis');

/* GET home page. */
router.get('/', function (req, res, next) {
  res.json({
    success: true,
    data: {
      env: process.env.ENV
    }
  });
});

router.get('/set', function (req, res, next) {
  redis.set(req.query.key, req.query.val);
  res.json({
    success: true
  });
});

router.get('/get', function (req, res, next) {
  redis.get(req.query.key, function (err, result) {
    if (err) {
      res.json({
        success: false,
        data: err
      });
    } else {
      res.json({
        success: true,
        data: result
      });
    }
  });
});

module.exports = router;